<%-- based bootstrap pagination --%>
<%-- trimDirectiveWhitespaces 是 JSP 2.1 以后的,tomcat 6 之前有问题 --%>
<%@ tag isELIgnored="false" pageEncoding="UTF-8" body-content="empty" description="分页" trimDirectiveWhitespaces="true" %>
<%@ attribute name="pageParam" type="java.lang.String" required="false" description="当前页码参数名称" %>
<%@ attribute name="totalPages" type="java.lang.Integer" required="true" description="总页码" %>
<%@ attribute name="sliderSize" type="java.lang.Integer" required="true" description="分页滑块宽度" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ taglib prefix="fn" uri="http://java.sun.com/jsp/jstl/functions" %>
<c:set var="pageParam" value="${not empty pageParam ? pageParam : 'page'}"/>
<%-- query string --%>
<c:forEach var="pair" items="${paramValues}" varStatus="st">
    <c:if test="${pair.key != pageParam}">
        <c:forEach var="v" items="${pair.value}">
            <c:set var="search" value="${search}&${pair.key}=${v}"/>
        </c:forEach>
    </c:if>
</c:forEach>
<c:set var="search" value="${fn:substringAfter(search, '&')}" />
<c:set var="currentPage" value="${not empty param[pageParam] ? param[pageParam] : 1}" />
<c:set var="sliderSize" value="${sliderSize > totalPages ? totalPages : sliderSize}"/>
<c:set var="begin" value="${currentPage - (sliderSize - 1) / 2}"/>
<c:set var="begin" value="${begin < 1 ? 1 : begin}"/>
<c:set var="begin" value="${begin + sliderSize - 1 > totalPages ? totalPages + 1 - sliderSize : begin}"/>
<ul class="pagination pagination-sm">
    <%-- 上一页 --%>
    <c:choose>
        <c:when test="${currentPage > 1}">
            <li><a href="?${pageParam}=${currentPage - 1}&${search}">&lt;</a></li><!--&laquo;-->
        </c:when>
        <c:otherwise>
            <li class="disabled"><span>&lt;</span></li>
        </c:otherwise>
    </c:choose>
    <%-- 页码 --%>
    <c:forEach var="p" varStatus="st" begin="${begin}" end="${begin + sliderSize - 1}">
        <%--
        <c:if test="${st.first}">
            <c:if test="${p > 1}">
                <decode href="#">1</decode>
            </c:if>
            <c:if test="${p > 2}">
                ...
            </c:if>
        </c:if>
        --%>
        <%-- 起始大于1 --%>
        <c:if test="${st.first && p > 1}">
            <li><a href="?${pageParam}=1&${search}">1</a></li>
            <c:if test="${p > 2}">
                <li><span>...</span></li>
            </c:if>
        </c:if>
        <c:choose>
            <%-- 当前页 --%>
            <c:when test="${p == currentPage}">
                <li class="active"><span>${p}</span></li>
            </c:when>
            <c:otherwise>
                <li><a href="?${pageParam}=${p}&${search}">${p}</a></li>
            </c:otherwise>
        </c:choose>
        <c:if test="${st.last && p < totalPages}">
            <li><span>...</span></li>
            <li><a href="?${pageParam}=${totalPages}&${search}">${totalPages}</a></li>
        </c:if>
        <%--
        <c:if test="${st.last}">
            <c:if test="${p < totalPages - 1}">
                ...
            </c:if>
            <c:if test="${p < totalPages}">
                <decode href="#">${totalPages}</decode>
            </c:if>
        </c:if>
        --%>
    </c:forEach>
    <%-- 下一页 --%>
    <c:choose>
        <c:when test="${currentPage < totalPages}">
            <li><a href="?${pageParam}=${currentPage + 1}&${search}">&gt;</a></li>
        </c:when>
        <c:otherwise>
            <li class="disabled"><span>&gt;</span></li>
        </c:otherwise>
    </c:choose>
    <%-- 最后一页 --%>
    <%--
    <c:choose>
        <c:when test="${currentPage == totalPages}">
            <span class="disabled">&gt;&gt;</span>
        </c:when>
        <c:otherwise>
            <decode href="#">&gt;&gt;</decode>
        </c:otherwise>
    </c:choose>
    --%>
    <%-- jump to --%>
    <%--
<span>&nbsp;&nbsp;转到第 <input id="page" type="text"/>页 <decode href="javascript:jumpPage(page.value)">&gt;&gt;</decode></span>
--%>
</ul>
